package com.cloud.mall.test.service;

import com.cloud.mall.test.mapper.StorageTblMapper;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 梁二东
 * @Date: 2024/12/16 10:33
 * @Description:
 **/
@Service
@Slf4j
public class StorageTblServiceImpl implements StorageTblService {

    @Autowired
    StorageTblMapper storageTblMapper;

    @Override
    public void deduct(String commodityCode, int count) {
        String xid = RootContext.getXID();
        log.info("开始扣减库存，全局事务xid：【{}】", xid);
        storageTblMapper.deduct(commodityCode, count);
        log.info("完成扣减库存，全局事务xid：【{}】", xid);
//        try {
//            Thread.sleep(10000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
    }
}
